import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    name: 'Main',
    component: () => import('../views/Main.vue'),
    meta: {
      title: 'Main',
      keepAlive: true
    },
    redirect: 'home',
    children: [
      {
        path: 'home',
        name: 'Home',
        component: () => import('@/views/Home.vue'),
        meta: {
          title: '首页',
          keepAlive: true
        }
      },
      {
        path: 'user',
        name: 'User',
        component: () => import('@/views/User.vue'),
        meta: {
          title: '用户信息',
          keepAlive: true
        },
        children: [
          {
            path: 'edit',
            name: 'UserEdit',
            component: () => import('@/views/UserEdit.vue'),
            meta: {
              title: '编辑用户信息',
              keepAlive: true
            }
          },
          {
            path: 'chat',
            name: 'UserChat',
            component: () => import('@/views/UserChat.vue'),
            meta: {
              title: '小思同学',
              keepAlive: true
            }
          }
        ]
      }
    ]

  },

  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/Login.vue'),
    meta: {
      title: '登录页面'
    }
  },
  {
    path: '/search',
    name: 'Search',
    component: () => import('@/views/Search.vue'),
    meta: {
      title: '搜索',
      keepAlive: true
    }
  },
  {
    path: '/search/:kw',
    name: 'SearchResult',
    component: () => import('@/views/SearchResult.vue')
  },
  {
    path: '/article/:id',
    name: 'Article',
    component: () => import('@/views/Article.vue')
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

export default router
